package com.demo.Test;


import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;

public class Test {

    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        String url= "jdbc:mysql://106.13.7.203:3306/wg12?useCursorFetch=true&amp;autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=UTF-8";
        String username = "root";
        String password = "Asd6250390@";
        Class.forName("com.mysql.jdbc.Driver");
        Connection conn = DriverManager.getConnection(url, username, password);
        System.out.println("连接成功");

        Statement st = conn.createStatement();
        String sql = "select * from users";
        ResultSet rs = st.executeQuery(sql);
        ArrayList<HashMap> ah = new ArrayList<>();
        while (rs.next()){
            HashMap h = new HashMap();
            h.put("id", rs.getInt("id"));
            h.put("name", rs.getString("name"));
            h.put("gender", rs.getString("gender"));
            h.put("age", rs.getInt("age"));
            ah.add(h);
        }
        System.out.println(ah);
        rs.close();
        st.close();
    }
}
